// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { time } from "./cases/utils/DecoratorTool";


const { ccclass, property } = cc._decorator;

export interface A {
    a: string;
}

@ccclass
export default class NewClass extends cc.Component {
    @property(cc.Graphics)
    graphics: cc.Graphics = null;

    private direction: cc.Vec2 = null;
    private speed: number = Math.PI;
    private times: number = 100000;
    private arr: string[] = [];
    private obj: object = {};
    private map: Map<number, number> = new Map();

    protected onLoad(): void {
        // this.letFunc();
        // this.arrFunc();
        // this.clearArr();
        // this.objFunc();
        // this.mapFunc();

        // for (let i = 0, len = this.times; i < len; i++) {
        //     let key = "Com." + i + "Com." + i;
        //     this.obj[i] = key;
        //     this.arr[i] = key;
        // }

        // this.str();
        // https://pan.baidu.com/s/1fDEg5LSsM4N0wSbLtG9Iww?pwd=cew7 
    }

    sort(arr) {
        let obj = new Map();
        let result = [];
        for (let v of arr) {
            if (!obj[v]) {
                obj[v] = 1;
                result.push(v);
            }
        }
        return result;
    }

    @time("lefFunc")
    private letFunc() {
        for (let i = 0; i < this.times; i++) {
            // var j = i + 1;
        }
    }



    @time("arrFunc")
    private arrFunc() {
        // let arr = this.arr;
        // for (let i = 0; i < this.times; i++) {
        //     arr.push(i);
        // }
    }

    @time("clearArr")
    private clearArr() {
        this.arr.length = 0;
    }

    @time("objFunc")
    private objFunc() {
        let obj = this.obj;
        for (let i = 0; i < this.times; i++) {
            obj[i] = i;
        }
    }

    @time("mapFunc")
    private mapFunc() {
        let map = this.map;
        for (let i = 0; i < this.times; i++) {
            map.set(i, i);
        }
    }

    @time("string")
    private str() {
        let t1 = 0, t2 = 0, start = 0;
        for (let i = 0, len = this.times; i < len; i++) {
            // start = Date.now();
            // let key = "Com." + i + "Com." + i;
            // this.arr.indexOf(key);
            // t1 += Date.now() - start;
            // start = Date.now();
            // this.obj[i] = "Com." + i;
            // t2 += Date.now() - start;
        }
        // cc.log("t1 %s t2", t1, t2);
    }

    protected update(dt: number): void {
        // this.direction.rotateSelf(-this.speed * dt);
        // this.graphics.clear();
        // this.graphics.moveTo(0, 0);
        // this.graphics.lineTo(this.direction.x, this.direction.y);
        // this.graphics.stroke();
        // let filter = ['scene'];
        // let f1 = Editor.Ipc.sendToMain;
        // Editor.Ipc.sendToMain = function (message, ...args) {
        //     log('sendToMain', message);
        //     f1(message, ...args);
        // }
        // let f2 = Editor.Ipc.sendToPanel;
        // Editor.Ipc.sendToPanel = function (message, ...args) {
        //     log('sendToPanel', message);
        //     f2(message, ...args);
        // }
        // let f3 = Editor.Ipc.sendToMainWin;
        // Editor.Ipc.sendToMainWin = function (message, ...args) {
        //     log('sendToMainWin', message);
        //     f3(message, ...args);
        // }
        // let f4 = Editor.Ipc.sendToWins;
        // Editor.Ipc.sendToWins = function (message, ...args) {
        //     log('sendToWins', message);
        //     f4(message, ...args);
        // }
        // let f5 = Editor.Ipc.sendToAll;
        // Editor.Ipc.sendToAll = function (message, ...args) {
        //     log('sendToAll', message);
        //     f5(message, ...args);
        // }

        // function log(title, message) {
        //     filter.indexOf(message) === -1 && console.log(title, message);
        // }
    }
}
